<template>
  <div>
    <button @click="modelbtn = true">弹出一个模态框</button>

    <teleport to="body"> 
          <div  class="model" v-if="modelbtn">
             <div>这是一个弹窗，我的父级是body
                 <button @click="modelbtn = false">关闭</button>
             </div>
             
          </div>
    </teleport>
  </div>
</template>


<script>
import {ref} from 'vue'
export default {
  setup() {
   let modelbtn = ref(false)
   return {modelbtn}
  },
};
</script>
<style scoped>
.model{
    position: absolute;
    top:  0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    flex-direction: column;
    align-content: center;
    justify-content: center;
}
.model div{
    display: flex;
     flex-direction: column;
    align-content: center;
    justify-content: center;
    background: white;
    width: 300px;
    height: 300px;
    padding: 5px;
}
.model button{
    width: 50px;
    text-align: center;
}
</style>